#include "mainscene.h"
#include "ui_mainscene.h"
#include"mypushbutton.h"
#include<QPainter>
#include<QPixmap>
#include<QTimer>
#include<QSoundEffect>

mainscene::mainscene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::mainscene)
{
    ui->setupUi(this);
    setFixedSize(320,558);
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    setWindowTitle("翻金币主页面");

    //信号和槽的退出事件
    connect(ui->actionQuit,&QAction::triggered,[=](){
        this->close();
    });
    QSoundEffect *startSound=new QSoundEffect(this);
    startSound->setSource(QUrl::fromLocalFile(":/res/TapButtonSound.wav"));


    MyPushButton* startBut=new MyPushButton(":/res/MenuSceneStartButton.png");
    startBut->setParent(this);
    startBut->move(this->width()*0.5-startBut->width()*0.5,this->height()*0.7);

    chooseLevel=new ChooseLevelScene();
    connect(chooseLevel,&ChooseLevelScene::chooseSceneBack,[=](){
        this->setGeometry(chooseLevel->geometry());
        chooseLevel->hide();
        this->show();
    });

    connect(startBut,&MyPushButton::clicked,[=](){

        startSound->play();

        //qDebug() <<"点击了开始按钮";
        startBut->zoom(false);
        startBut->zoom(true);
        //延时进入
        QTimer::singleShot(500,this,[=](){
            chooseLevel->setGeometry(this->geometry());
            this->hide();
            chooseLevel->show();
        });
    });
}
void mainscene::paintEvent(QPaintEvent *event){
    //隐式调用类的构造函数 QPainter painter=QPainter(this);QPixmap pix=QPixmap();
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    pix.load(":/res/Title.png");
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);

    painter.drawPixmap(10,30,pix);

}

mainscene::~mainscene()
{
    delete ui;
}

